<?php

namespace App\Api;
use App\Domain\User\User as UserDomain;
use PhalApi\Api;


/**
 * 非常简单-检测项目
 *
 * @author: dogstar <chanzonghuang@gmail.com> 2014-10-04
 */
class FcjdCheckItem extends Api
{

    public function getRules()
    {
        return array(
            // 单位管理设置
            'getCheckItem'       => array(
                'username'  => array('name' => 'username', 'require' => true, 'desc' => '用户名'),
            ),
        );
    }


    /**
     * 检测项目
     * @desc 更新个人信息
     * @return array data 签名url
     * @exception 400 非法请求，参数传递错误
     */
    public function getCheckItem()
    {
        // 最简单的处理方式
        header('Access-Control-Allow-Origin: *');
        header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
        header('Access-Control-Allow-Headers: *');

        $username = $this->username;
        
        if( $username ){
            $domain = new UserDomain();
            $user = $domain->getUserByUsername($username, '*');
            if ($user) {
                $checkItem = \PhalApi\DI()->notorm->idcard_fcjd_unit->where('name', $user['unit'])->fetchOne();
                return array(
                    'checkItem' => json_decode($checkItem['drug'], true),
                    'all' => $checkItem
                );
           }
        }
    }
}
